package com.boss.salary.service.impl;

import com.boss.common.entity.PageDTO;
import com.boss.common.util.DateUtils;
import com.boss.framework.dto.PaginationDTO;
import com.boss.salary.dao.IPersonSalaryInfoDao;
import com.boss.salary.entity.PersonSalaryInfo;
import com.boss.salary.service.IPersonSalaryInfoService;
import com.boss.sys.utils.SysUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PersonSalaryInfoServiceImpl implements IPersonSalaryInfoService {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(PersonSalaryInfoServiceImpl.class);

    @Autowired
    private IPersonSalaryInfoDao dao;


    @Override
    public PageDTO<PersonSalaryInfo> queryPersonSalaryInfoPage(PaginationDTO paginationDTO) {
        List<PersonSalaryInfo> list = dao.queryPersonSalaryInfoPage(paginationDTO);
        int total = dao.queryPersonSalaryInfoTotal();
        PageDTO<PersonSalaryInfo> pageDTO = new PageDTO<>();
        pageDTO.setRows(list);
        pageDTO.setTotal(total);
        return pageDTO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void savePersonSalaryInfo(PersonSalaryInfo personSalaryInfo) {
        personSalaryInfo.setId(SysUtils.generateGuid());
        personSalaryInfo.setCreateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        personSalaryInfo.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        personSalaryInfo.setIsDeleted(0);
        dao.savePersonSalaryInfo(personSalaryInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updatePersonSalaryInfo(PersonSalaryInfo personSalaryInfo) {
        personSalaryInfo.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        dao.updatePersonSalaryInfo(personSalaryInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deletePersonSalaryInfo(String id) {
        dao.deletePersonSalaryInfo(id);
    }
}
